﻿@using LuDragon.Data.Entities;
@{
    ViewBag.Title = "NavigationEdit";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";

    List<Sys_Navigation> parentNavList = ViewBag.ParentNavList;//父级菜单
    Sys_Navigation navInfo = ViewBag.NavInfo;//菜单信息  为null则新增 反之编辑
}

<span class="layui-breadcrumb">
    <a>系统设置</a>
    <a>菜单导航</a>
    <a><cite>编辑</cite></a>
</span>
<hr />
<form class="layui-form" method="post" action="Save" id="form1">
    <table class="layui-table layui-table-add layui-table-detail" lay-skin="nob">
        <tbody>
            <tr>
                <th>父级菜单</th>
                <td>
                    <div class="width">
                        <select lay-verify="" id="parentNav">
                            <option value="0">无</option>
                            @for (int i = 0; i < parentNavList.Count; i++)
                            {
                                if (parentNavList[i].NavId != (navInfo?.NavId))
                                {
                                    <option value="@parentNavList[i].NavId">@parentNavList[i].NavName</option>
                                }
                            }
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <th><span class="red">*</span>菜单名称</th>
                <td>
                    <div class="width">
                        <input type="text" name="NavName" placeholder="请输入菜单名称" autocomplete="off" class="layui-input" value="@(navInfo?.NavName)">
                    </div>
                </td>
            </tr>
            <tr>
                <th><span class="red"></span>链接地址</th>
                <td>
                    <div class="width">
                        <input type="text" name="Url" placeholder="请输入链接地址" autocomplete="off" class="layui-input" value="@(navInfo?.Url)">
                    </div>
                </td>
            </tr>
            <tr>
                <th><span class="red"></span>是否启用</th>
                <td>
                    <div class="width">
                        <input type="checkbox" checked="@(navInfo?.Enabled)" lay-skin="switch" lay-text="是|否" id="check">
                    </div>
                </td>
            </tr>
            <tr>
                <th><span class="red"></span>排序</th>
                <td>
                    <div class="width">
                        <input type="number" name="Sort" placeholder="越小越靠前" autocomplete="off" class="layui-input" value="@(navInfo?.Sort)">
                    </div>
                </td>
            </tr>

        </tbody>
    </table>
    <div class="layui-button">
        <button class="layui-btn" id="save">保存</button>
        <button type="reset" class="layui-btn layui-btn-primary" onclick="javascript: history.back();">返回上一页</button>
    </div>
    <input type="hidden" name="ParentId" value="0" id="parentId" />
    <input type="hidden" name="Enabled" value="false" id="enabled" />
    <input type="hidden" name="NavId" value="@(navInfo?.NavId)" />
    <input type="hidden" name="IsSystem" value="@(navInfo?.IsSystem)" />
</form>
<script>
    //下拉框赋值
    var selectVal = "@(navInfo?.ParentId)";
    $("#parentNav").val(selectVal);
    //保存
    $("#save").click(function () {
        $("#parentId").val($("#parentNav").val());
        $("#enabled").val($("#check").is(":checked") ? true : false);
        $("#form1").ajaxForm(function (result) {
            var data = JSON.parse(result);
            if (data.Code == 200) {
                dialog.prompt("保存成功");
                location.href = "NavigationList";
            } else {
                dialog.prompt("操作失败，请稍后重试");
            }
        });
    });
</script>